package com.zenob.kindle.helloworld;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flowme.util.Color;
import com.flowme.widget.KindleView;

public class HelloView extends KindleView implements OnClickListener {

	private TextView helloKindle;
	private Button button1;
	private Button button2;

	public HelloView() {

		LinearLayout ll = new LinearLayout();
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams();
		lp.setMargins(5, 5, 5, 5);
		lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;
		lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
		lp.gravity = Gravity.CENTER_HORIZONTAL;

		ll.setOrientation(LinearLayout.VERTICAL);

		helloKindle = new TextView();
		helloKindle.setPadding(20, 20, 20, 20);
		helloKindle.setText("Hello Kindle");
		helloKindle.setTextColor(Color.BLACK);
		helloKindle.setGravity(Gravity.CENTER);

		button1 = new Button();
		button1.setText("Open Dialog");
		button1.setOnClickListener(this);

		button2 = new Button();
		button2.setText("Open Menu");
		button2.setOnClickListener(this);

		ll.addView(helloKindle, lp);
		ll.addView(button1, lp);
		ll.addView(button2, lp);
		ll.setPadding(10, 10, 10, 10);
		addView(ll);

	}

	public void onClick(View v) {

		if (v.equals(button1)) {
			AlertDialog dialog = new AlertDialog();
			dialog.setTitle("Simple dialog");
			dialog.setButton(Dialog.BUTTON_NEGATIVE, "Close", new Dialog.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			dialog.show();
		} else if (v.equals(button2)) {
			openMenu();
		}
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		
		menu.add("Option 1");
		menu.add("Option 2");
		menu.add("Option 3");
		
		return super.onCreateOptionsMenu(menu);
	}
	
	
}
